<!--{include header_html}-->	
<script language="javascript">
	//检查表单数据的合法性
	function formCheck()
	{
		if($('#item_name').val() == '')
		{
			messageError('请填写菜单名称！');
			return false;
		}
		if($('#item_ctrl').val() == '')
		{
			messageError('请选择一个控制器！');
			return false;
		}
		if($('#item_act').val() == '')
		{
			messageError('请选择一个动作！');
			return false;
		}
		return true;
	}

	//处理表单
	function formResult(res, status)
	{
		//alert(res);
		if(status == 'success')
		{
			if(res == 1)
			{
				messageSuccess('操作已成功！');
				//document.getElementById('addform').reset();
				listFather();
				listControl();
				//listAction();
				return false;
			}
			else if(res == -10)
			{
				messageError('菜单名称不能为空！');
				return false;
			}
			else if(res == -11)
			{
				messageError('控制器名称不能为空！');
				return false;
			}
			else if(res == -12)
			{
				messageError('动作名称不能为空！');
				return false;
			}
			else
			{
				messageError('系统异常，请联系管理员！');
				return false;
			}
		}
    	else
		{
			messageError('网络异常，请检查网络连接！');
		} 
		return true;
	}

	//列出对应控制器中所有的动作
	function listAction(obj)	
	{
		$.ajax({
			url: 'manage.php?c=sysmenu&a=listaction&id='+{$nowmenu['id']}+'&cn='+obj.value+'&t='+new Date().getTime(),
			type: 'get',
			dataType: 'json',
			success: function(res){		
				var opt = '';
				if(res.length < 1){
					opt += '<option value="">无</option>';
				}else{
					for(x in res){
						var sel = '';
						if(res[x]['sel'] == 1) sel = ' selected';
						opt += '<option value="'+res[x]['name']+'"'+sel+'>'+res[x]['name']+'</option>';
					}
				}
				$('#item_act').html(opt);
				return true;
			}
		})
	}
	
	//列出所有控制器的名称
	function listControl()
	{
		$.ajax({
			url: 'manage.php?c=sysmenu&a=listcontrol&id='+{$nowmenu['id']}+'&t='+new Date().getTime(),
			type: 'get',
			dataType: 'json',
			success: function(res){		
				var opt = '<option value="">请选择</option>';
				for(x in res){
					var sel = '';
					if(res[x]['sel'] == 1) sel = ' selected';
					opt += '<option value="'+res[x]['name']+'"'+sel+'>'+res[x]['name']+'&nbsp;('+res[x]['num']+')</option>';
				}
				$('#item_ctrl').html(opt);
				return true;
			}
		})
	}
	
	//列出所有父级菜单名称
	function listFather()
	{
		$.ajax({
			url: 'manage.php?c=sysmenu&a=listfather&id='+{$nowmenu['id']}+'&t='+new Date().getTime(),
			type: 'get',
			dataType: 'json',
			success: function(res){		
				var opt = '<option value="0">无父级</option>';
				for(x in res){
					var sel = '';
					if(res[x]['sel'] == 1) sel = ' selected';
					opt += '<option value="'+res[x]['id']+'"'+sel+'>'+res[x]['name']+'</option>';
				}
				$('#item_fid').html(opt);
				return true;
			}
		})
	}
</script>

	<!--表单START-->
	<form name="addform" id="addform" action="" method="post" class="ajaxForm">
	<table width="450"  class="addtbl">
		<tr>
            <td width="100" align="right">菜单名称:</td>
            <td width="350">
            	<input type="hidden" name="item[id]" id="item_id" value="{$nowmenu['id']}" />
	            <input type="text" name="item[name]" id="item_name" value="{$nowmenu['name']}" />
	            <span style="color:red">*</span> <span class="notes">一般不超过5个字,请不要过长</span>
            </td>
        </tr>
        <tr>
            <td align="right">父级菜单:</td>
            <td>
	            <select name="item[fid]" id="item_fid">
	            	<option value="0">无父级</option>
		        <!--{loop $tree['order'] $index $one}-->
					<option value="{$tree['menu'][$one]['id']}" <!--{if $nowmenu['fid'] == $tree['menu'][$one]['id']}-->selected<!--{/if}-->>
					<!--{if $tree['deep'][$index] != 1}-->
						<!--{if !isset($tree['deep'][$index+1]) || $tree['deep'][$index+1] < $tree['deep'][$index]}-->
						└
						<!--{else}-->
						├
						<!--{/if}-->
						${str_repeat(' -', $tree['deep'][$index] - 2)}
					<!--{/if}-->
					{$tree['menu'][$one]['name']}&nbsp;({$one})
					</option>
	            <!--{/loop}-->
	            </select>
	            <span style="color:red">*</span> <span class="notes">理论可支持无限级，一般最多为5级</sapn>
            </td>
        </tr>
        <tr>
             <td align="right">控制器名:</td>
             <td>
	             <select name="item[ctrl]" id="item_ctrl" onchange="listAction(this)">
					<option value="">请选择</option>
	             	<!--{loop $ctrls $index $one}-->
	             		<option value="{$one['name']}" <!--{if $nowmenu['ctrl'] == $one['name']}-->selected<!--{/if}-->>
	             			{$one['name']}&nbsp;({$one['num']})
						</option>
	             	<!--{/loop}-->
	             </select>
	             <span style="color:red">*</span> <span class="notes">选择菜单所对应的控制器文件名</span>
             </td>
        </tr>
        <tr>
             <td align="right">动作名称:</td>
             <td>
				<select name="item[act]" id="item_act">
	             	<option value="">请选择</option>
	             </select>
	             <span style="color:red">*</span> <span class="notes">选择菜单所对应的控制器中的动作名</span>
			 </td>
        </tr>
		<script>listAction(document.getElementById('item_ctrl'))</script>
        <tr>
             <td align="right">打开目标:</td>
             <td>
             <select name="item[target]" id="item_target">
             	<option value="self" <!--{if $nowmenu['target'] == 'self'}-->selected<!--{/if}-->>本窗口</option>
             	<option value="blank" <!--{if $nowmenu['target'] == 'blank'}-->selected<!--{/if}-->>新窗口</option>
             	<option value="iframe" <!--{if $nowmenu['target'] == 'iframe'}-->selected<!--{/if}-->>浮层子窗口</option>
             	<option value="ajax" <!--{if $nowmenu['target'] == 'ajax'}-->selected<!--{/if}-->>浮层异步窗口</option>
             </select>
			 <span style="color:red">*</span> <span class="notes">选择菜单以何种方式被打开</span>
             </td>
        </tr>
        <tr>
             <td align="right">菜单类型:</td>
             <td>
				 <select name="item[mtype]" id="item_mtype">
	             	<!--{loop $mtypes $index $one}-->
	             		<option value="{$index}" <!--{if $nowmenu['mtype'] == $index}-->selected<!--{/if}-->>{$one}</option>
	             	<!--{/loop}-->
	             </select>
	             <span style="color:red">*</span> <span class="notes">选择菜单的所属类型 </span>
			 </td>
        </tr>
        <tr>
             <td align="right">菜单权重:</td>
             <td>
             	<input type="text" name="item[weight]" id="item_weight" style="width:40px;" value="{$nowmenu['weight']}" />
             	 <span style="color:red"></span> <span class="notes">权重值越大,排序越会靠前</span>
             	</td>
        </tr>
        <!--<tr>
             <td align="right">是否默认:</td>
             <td>
				 <select name="item[isindex]" id="item_isindex">
	             	<option value="0">否</option>
	             	<option value="1">是</option>
	             </select>
	             <span style="color:red"></span> <span class="notes">当为默认时,打开父级菜单时其将被默认打开 </span>
			 </td>
        </tr>-->
        <tr>
             <td align="right">是否前台隐藏:</td>
             <td>
				 <select name="item[ishide]" id="item_ishide">
	             	<option value="0" <!--{if $nowmenu['ishide'] == 0}-->selected<!--{/if}-->>否</option>
	             	<option value="1" <!--{if $nowmenu['ishide'] == 1}-->selected<!--{/if}-->>是</option>
	             </select>
	             <span style="color:red"></span> <span class="notes">当为隐藏时,在菜单列表中不显示但仍可按权限访问</span>
			 </td>
        </tr>
        <tr>
			 <td align="right" valign="top">菜单说明:</td>
			 <td>
			 	<textarea name="item[notes]" id="item_notes" style="width:280px;height:60px;" />{$nowmenu['notes']}</textarea>
			 </td>
		</tr>
        <tr>
			 <td colspan="2" align="center" height="40">
				<input type="submit" name="handin" id="handin" value="提 交" class="button_1" />
			 </td>
		</tr>
	</table>
	</form>
	<!--表单END-->

<!--{include footer_html}-->





